#include<iostream>
#define int long long
#define endl '\n'
using namespace std;
signed main() 
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int T;
    cin >> T;
    while (T--) 
    {
        int a, b;
        cin >> a >> b;
        if (a == b)
            cout << 0 << endl;
        else
        {
            if (((a & b) == b) || ((a | b) == b))
                cout << 1 << endl;
            else cout << 2 << endl;
        }
        //	int a=8&4;
        //	int b=8|4;
        //	cout<<a<<" "<<b<<endl;   
    }

    return 0; 
}


